package com.gxuwz.service.impl;

import com.gxuwz.dao.LoginDao;
import com.gxuwz.entity.Instructor;
import com.gxuwz.entity.Student;
import com.gxuwz.entity.User;
import com.gxuwz.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginDao loginDao;

    /**
     * 登录，判断该身份为什么，到对应的表去查询
     * @param userInfo 身份信息
     * @return
     */
    public Object checkUser(Map<String, Object> userInfo) {
        String identity = (String) userInfo.get("identity");
        if(identity.equals("系统管理员")){
            User user = new User();
            user.setUserId((String) userInfo.get("username"));
            user.setPassword((String) userInfo.get("password"));
            return loginDao.selectUser(user);
        } else if(identity.equals("辅导员")){
            Instructor instructor = new Instructor();
            instructor.setInstID((String) userInfo.get("username"));
            instructor.setPassword((String) userInfo.get("password"));
            return loginDao.selectInstructor(instructor);
        } else {
            Student student = new Student();
            student.setStuID((String) userInfo.get("username"));
            student.setPassword((String) userInfo.get("password"));
            return loginDao.selectStudent(student);
        }
    }

}
